package top.guinguo.analyzer_03.util;

import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.MaxWordSeg;
import com.chenlb.mmseg4j.analysis.MMSegTokenizer;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;

import java.io.Reader;

/**
 * Created by guin_guo on 2016/12/22.
 */
public final class MySameAnalyzer extends Analyzer {

    private SameWordContext sameWordContext;

    public MySameAnalyzer(SameWordContext sameWordContext) {
        this.sameWordContext = sameWordContext;
    }

    public TokenStream tokenStream(String fieldName, Reader reader) {
        Dictionary dic = Dictionary.getInstance("E:\\test\\lucene\\data");
        return new MySameTokenFilter(
                new MMSegTokenizer(new MaxWordSeg(dic), reader), sameWordContext
        );
    }
}
